<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Alignment (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Alignment (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Alignment (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C-Extensions.html" rel="up" title="C Extensions">
<link href="Inline.html" rel="next" title="Inline">
<link href="Character-Escapes.html" rel="prev" title="Character Escapes">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Alignment">
<div class="nav-panel">
<p>
Next: <a href="Inline.html" accesskey="n" rel="next">An Inline Function is As Fast As a Macro</a>, Previous: <a href="Character-Escapes.html" accesskey="p" rel="prev">The Character <kbd class="key">ESC</kbd> in Constants</a>, Up: <a href="C-Extensions.html" accesskey="u" rel="up">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Determining-the-Alignment-of-Functions_002c-Types-or-Variables"><span>6.44 Determining the Alignment of Functions, Types or Variables<a class="copiable-link" href="#Determining-the-Alignment-of-Functions_002c-Types-or-Variables"> &para;</a></span></h3>
<a class="index-entry-id" id="index-alignment"></a>
<a class="index-entry-id" id="index-type-alignment"></a>
<a class="index-entry-id" id="index-variable-alignment"></a>

<p>The keyword <code class="code">__alignof__</code> determines the alignment requirement of
a function, object, or a type, or the minimum alignment usually required
by a type.  Its syntax is just like <code class="code">sizeof</code> and C11 <code class="code">_Alignof</code>.
</p>
<p>For example, if the target machine requires a <code class="code">double</code> value to be
aligned on an 8-byte boundary, then <code class="code">__alignof__ (double)</code> is 8.
This is true on many RISC machines.  On more traditional machine
designs, <code class="code">__alignof__ (double)</code> is 4 or even 2.
</p>
<p>Some machines never actually require alignment; they allow references to any
data type even at an odd address.  For these machines, <code class="code">__alignof__</code>
reports the smallest alignment that GCC gives the data type, usually as
mandated by the target ABI.
</p>
<p>If the operand of <code class="code">__alignof__</code> is an lvalue rather than a type,
its value is the required alignment for its type, taking into account
any minimum alignment specified by attribute <code class="code">aligned</code>
(see <a class="pxref" href="Common-Variable-Attributes.html">Common Variable Attributes</a>).  For example, after this
declaration:
</p>
<div class="example smallexample">
<pre class="example-preformatted">struct foo { int x; char y; } foo1;
</pre></div>

<p>the value of <code class="code">__alignof__ (foo1.y)</code> is 1, even though its actual
alignment is probably 2 or 4, the same as <code class="code">__alignof__ (int)</code>.
It is an error to ask for the alignment of an incomplete type other
than <code class="code">void</code>.
</p>
<p>If the operand of the <code class="code">__alignof__</code> expression is a function,
the expression evaluates to the alignment of the function which may
be specified by attribute <code class="code">aligned</code> (see <a class="pxref" href="Common-Function-Attributes.html">Common Function Attributes</a>).
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Inline.html">An Inline Function is As Fast As a Macro</a>, Previous: <a href="Character-Escapes.html">The Character <kbd class="key">ESC</kbd> in Constants</a>, Up: <a href="C-Extensions.html">Extensions to the C Language Family</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
